// store/user.js
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: localStorage.getItem('token'),
    userInfo: JSON.parse(localStorage.getItem('userInfo') || '{}'),
    dynamicRoutesAdded: false
  }),
  actions: {
    setToken(token) {
      this.token = token
      localStorage.setItem('token', token)
    },
    setUserInfo(info) {
      this.userInfo = info
      localStorage.setItem('userInfo', JSON.stringify(info))
    },
    reset() {
      this.token = ''
      this.userInfo = {}
      this.dynamicRoutesAdded = false
      localStorage.removeItem('token')
      localStorage.removeItem('userInfo')
      conosole.log('重置用户信息')
    }
  }
})
